﻿using AutoMapper;
using Common.Communal;
using ERP.Domain.CustomerSupplier;
using MediatR;
using Sell.Api.Write.Application.Command.SupplierCommand;
using Sell.Services.Suppliers;

namespace Sell.Api.Write.Application.CommandHandlers.SupplierCommandHandlers
{
    public class SupplierUpdateCommandHandlers : IRequestHandler<SupplierUpdateCommand, ApiResult<int>>
    {
        public IMapper Mapper { get; }
        public ISupplierServices supplier { get; }
        public SupplierUpdateCommandHandlers(ISupplierServices _supplier, IMapper _Mapper)
        {
            Mapper = _Mapper;
            supplier = _supplier;
        }
        /// <summary>
        /// 供应商管理修改
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        public async Task<ApiResult<int>> Handle(SupplierUpdateCommand request, CancellationToken cancellationToken)
        {
            var list = Mapper.Map<Supplier>(request);
            return await supplier.UpdateSupplier(list);
        }
    }
}
